package javachongkao.异常.设计一个能处理异常的Loan类;
//7-9 设计一个能处理异常的Loan类
//定义一个贷款类Loan，其中有属性：
//annualInterestRate:double，表示贷款的年利率（默认值：2.5）
//numberOfYears:int，表示贷款的年数（默认值：1）
//loanAmount:double,表示贷款额（默认值：100）
//loanDate:java.util.Date,表示创建贷款的日期
//定义方法：
//（1）默认的无参构造方法
//（2）带指定利率、年数和贷款额的构造方法
//（3）所有属性的get/set方法
//（4）返回这笔贷款的月支付额getMonthlyPayment()
//月支付额 = (贷款额度月利率)/(1-(1/Math.pow(1+月利率,年数12)))
//（5）返回这笔贷款的总支付额getTotalPayment()
//总支付额度 = 月支付额度年数12
import java.util.Date;
import java.util.Scanner;
public class Main7{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (input.hasNext()) {
            double AIR = input.nextDouble();
            int NOY = input.nextInt();
            double LA = input.nextDouble();
            try {
                Loan m = new Loan(AIR, NOY, LA);
                if (AIR<=0)throw new IllegalArgumentException("Annual interest rate must be positive");
                else if (NOY<=0)throw new IllegalArgumentException("Number of years must be positive");
                else if (LA<=0)throw new IllegalArgumentException("Loan amount must be positive");
                System.out.printf("%.3f\n",m.getTotalPayment());
            } catch (Exception ex) {
                System.out.println(ex);
            }
        }

    }
}

class Loan{
    private double annualInterestRate;
    private int numberOfYear;
    private double loanAmount;
    private Date loanDate;

    public Loan() {
        annualInterestRate=2.5;
        numberOfYear=1;
        loanAmount=100;
        this.loanDate=new Date();//没啥用
    }

    public Loan(double annualInterestRate, int numberOfYear, double loanAmount) {
        this.annualInterestRate = annualInterestRate;
        this.numberOfYear = numberOfYear;
        this.loanAmount = loanAmount;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

    public int getNumberOfYear() {
        return numberOfYear;
    }

    public void setNumberOfYear(int numberOfYear) {
        this.numberOfYear = numberOfYear;
    }

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    public Date getLoanDate() {
        return loanDate;
    }

    public void setLoanDate(Date loanDate) {
        this.loanDate = loanDate;
    }

    public double getMonthlyPayment(){
        double monthRate=annualInterestRate/1200;//注意年利率=月利率/1200;
        return loanAmount*monthRate/(1-(1/Math.pow(1+monthRate,numberOfYear*12)));
    }

    public double getTotalPayment(){
        return getMonthlyPayment()*12*numberOfYear;
    }
}
